﻿using NUnit.Framework;
using Pyxis.FluentSelenium.Locator;
using Selenium;

namespace Pyxis.FluentSelenium.SampleWebAppTest.SimpleExamples
{
    [TestFixture]
	public class RadioButtonsTest
	{
        private WebApplication application;
        private User user;

        private readonly RadioButtonLocator radioButtonOption1 = RadioButtonLocator.WithXpath("//input[@value='radioButton1']");
        private readonly RadioButtonLocator radioButtonOption2 = RadioButtonLocator.WithXpath("//input[@value='radioButton2']");

        [SetUp]
        public void Initialise()
        {
            application = new WebApplication(3000, "Pyxis.FluentSelenium.SampleWebApp");
            application.Start();

            var selenium = new DefaultSelenium("127.0.0.1", 4445, "*iexplore", "http://localhost:3000/");
            user = new User(selenium);
            user.Start();
        }

        [Test]
        public void TestSelectOption1()
        {
            user.Goto("SimpleExamples/RadioButton.aspx");
            user.For(radioButtonOption1).Selects();

            user.For(radioButtonOption1).ShouldBeChecked();
        }

        [Test]
        public void TestSelectOption1ThenSelectOption2UnselectOption1()
        {
            user.Goto("SimpleExamples/RadioButton.aspx");
            user.For(radioButtonOption1).Selects();
            user.For(radioButtonOption2).Selects();

            user.For(radioButtonOption1).ShouldNotBeChecked();
            user.For(radioButtonOption2).ShouldBeChecked();
        }

        [TearDown]
        public void Cleanup()
        {
            user.Stop();
            application.Stop();
        }
	}
}
